<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/jquery-3.4.1.js"></script>
    <script>
         //登录操作
    function login({ url, username, password }) {
      let promise = new Promise((resolve, reject) => {
        $.ajax({
          url,
          data: {
            username,
            password
          },
          type: 'GET',
          cache: false,
          success(res) {
            resolve(res)
          },
          error(e) {
            reject(e)
          }
        })
      })
      return promise
    }

    $(async function() {
      try {
        let res = await login({
          url: 'http://192.168.102.5:8888/api/private/v1/login',
          username: 'admin',
          password: '123456'
        })
        if (res.meta.status !== 200) {
          return alert('程序出错了')
        }
        sessionStorage.setItem('user', JSON.stringify(res.data))
        let id = setTimeout(function() {
          location = 'goods.html'
        }, 2000)
      } catch (e) {
        console.log(e)
      }
    })
    </script>
</head>
<body>
    <div id="app"></div>
</body>
</html>